#!/bin/bash
# 当前运行目录为项目的根目录

servers=("eureka" "zuul" "demo-api")version="0.0.1-SNAPSHOT"
server_name=""
jar_name=""

#也可以写成for element in ${array[*]}
for element in ${servers[@]}; do
    cd $element
    server_name=server-$element
    jar_name=./build/libs/$element-$version.jar  #发送命令，结束当前screen运行的jar
    
    # ctrl + c  发送命令, 结束当前screen
    screen -S $server_name -X stuff $'\003' 
    screen -S $server_name -X stuff 'exit\r' 
    
     # 使用gradle打包 ./gradlew bootJar 新建screen
    screen -dmS $server_name  
    screen -S $server_name -X stuff "java -jar ${jar_name}\r"
    
    echo "Finish $element $jar_name !!"
    cd ..
done